<?php

class Action
{
    public function index(){
        $search_filter = null;

        extract(URLTracker::init(array(
            'search_filter' => array(),
        )));
        $order_filter['type'] = 1;
        $order_filter['is_enable'] = 1;
        $order_filter['status'] = 1;
        $order_filter['progress != '] = 15;
        if (isset($search_filter['start_date']) && $search_filter['start_date']) {
            $order_filter['add_time >='] = $search_filter['start_date']." 00:00:00";
        }

        if (isset($search_filter['end_date']) && $search_filter['end_date']) {
            $order_filter['add_time <='] = $search_filter['end_date']." 23:59:59";
        }
        $order_id_list = _model("order")->getFields('id',$order_filter);
        $sku_message_list = records_center_helper::get_goods_message($order_id_list);
        $sku_message = array();
        $article_cate = records_center_config::$article_category;
        $goods_classify = records_center_config::$$search_filter['sku_name'];
        if($search_filter['sku_name'] == 'canning_popcorn'){
            foreach($goods_classify as $k => $v){
                $sku_message[] = records_center_helper::get_second_goods_message_by_goods_id($order_id_list, $k, $v);
            }
            foreach($sku_message as $k => $v){
                $sku_message[$k]['sku_name'] = $article_cate[$search_filter['sku_name']];
            }
        }elseif($search_filter['sku_name'] == 'device'){
            foreach($goods_classify as $k => $v){
                $sku_message[] = records_center_helper::get_second_goods_message_by_goods_id($order_id_list, $k, $v);
            }
            foreach($sku_message as $k => $v){
                $sku_message[$k]['sku_name'] = $article_cate[$search_filter['sku_name']];
            }
        }else{
            foreach($goods_classify as $k => $v){
                $sku_message[] = records_center_helper::get_goods_message_by_goods_id($order_id_list, $k);
            }

            foreach($sku_message as $k => $v){
                if(in_array($search_filter['sku_name'], array_flip(records_center_config::$canning_popcorn))){
                    $sku_message[$k]['sku_name'] = records_center_config::$canning_popcorn[$search_filter['sku_name']];
                }elseif(in_array($search_filter['sku_name'], array_flip(records_center_config::$device))){
                    $sku_message[$k]['sku_name'] = records_center_config::$device[$search_filter['sku_name']];
                }else{
                    $sku_message[$k]['sku_name'] = $article_cate[$search_filter['sku_name']];
                }

                $goods_information = _model('goods')->getList(array('id' => $v['goods_id']));
                if(!$goods_information){
                    unset($goods_information);
                    continue;
                }
                $sku_message[$k]['title'] = $goods_information[0]['title'];
                $sku_message[$k]['intro'] = $goods_information[0]['intro'];
                $sku_message[$k]['unit'] = $goods_information[0]['unit'];
                $sku_message[$k]['price'] = $goods_information[0]['price'];
            }
        }


        Response::assign('sku_message', $sku_message);
        Response::assign('search_filter', $search_filter);

        Response::display('admin/sku_statistics_list.html');
    }
}
?>